package jUtil;

import com.sun.istack.internal.NotNull;

import java.util.*;
import java.util.function.Consumer;

/**
 * @author ：黄淼淳
 * @date ：2021/12/20 13:15
 * @description：流式计算
 */
public class StreamDemo {
    public static void main(String[] args) {
        Person person = new Person("A", 21, "男");
        Person person1 = new Person("B", 22, "女");
        Person person2 = new Person("C", 23, "男");
        List<Person> list = Arrays.asList(person, person1, person2);

        list.stream().filter(t -> {
                    return t.getAge() > 21;
                }).map(t -> {
                    t.setName(t.getName().toLowerCase());
                    return t;
                }).sorted(/*(t1,t2)->{return t2.getAge()-t1.getAge();}*/).forEach(System.out::println);
    }
}

class Person implements Comparable<Person> {
    @NotNull
    private String name;
    @NotNull
    private Integer age;
    @NotNull
    private String sex;

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Person(String name, Integer age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    @Override
    public int compareTo(Person o) {
        return name.compareTo(o.getName());
    }
}
